Page({
  data: {
    visitorId: {},
    id: ''
  },
  onLoad ({ id }) {
    this.getVisitorId(id)
    this.setData({ id })
  },
  async saveImage () {
    const { path } = await wx.getImageInfo({
      src: this.data.visitorId.url
    })
    const res = await wx.saveImageToPhotosAlbum({
      filePath: path
    })
    console.log(res)
  },
  async getVisitorId (id) {
    const res = await wx.$http.get(`/visitor/${id}`)
    if (res.code !== 10000) return wx.$utils.toast()
    this.setData({
      visitorId: res.data
    })
  },
  onShareAppMessage () {
    return {
      title: '查看通行证',
      path: '/visitor_pkg/pages/passport/index?id=' + this.data.id,
      imageUrl: 'https://enjoy-plus.oss-cn-beijing.aliyuncs.com/images/share_poster.png'
    }
  }
})
